package cn.yunhe.services;

import cn.yunhe.dao.GuoDao;
import cn.yunhe.entity.Dirty;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class GuoService {
    SqlSession session = null;
    GuoDao guoDao = null;

    public String zang(String message) {
        try {
            session = SqlSessionFactoryUtil.getSqlSession();
            guoDao = session.getMapper(GuoDao.class);
            List<Dirty> list = guoDao.zang();

            for (Dirty dirty:list) {
                if (message.indexOf(dirty.getSpeak())!=-1) {
                    int num=dirty.getSpeak().length();
                    String str="";
                    for (int i = 0; i < num; i++) {
                        str+="*";
                    }
                    message=message.replace(dirty.getSpeak(),str);
                }
            }
            return message;

        } finally {
            session.close();
        }
    }

}
